<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>hitechnic-irseeker-v2-enhanced-SMUX-test1.c</h1>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><span class="preprocessor">#pragma config(Sensor, S1,     HTSMUX,              sensorI2CCustom)</span>
<span class="preprocessor"></span><span class="comment">//*!!Code automatically generated by &#39;ROBOTC&#39; configuration wizard               !!*//</span>

<span class="comment">/*</span>
<span class="comment"> * $Id: hitechnic-irseeker-v2-enhanced-SMUX-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
<span class="comment"></span>
<span class="comment">/**</span>
<span class="comment"> * hitechnic-irseeker-v2.h provides an API for the HiTechnic IR Seeker V2.  This program</span>
<span class="comment"> * demonstrates how to use that API.</span>
<span class="comment"> *</span>
<span class="comment"> * Changelog:</span>
<span class="comment"> * - 0.1: Initial release</span>
<span class="comment"> * - 0.2: Driver renamed to HTIRS2</span>
<span class="comment"> *</span>
<span class="comment"> * Credits:</span>
<span class="comment"> * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.</span>
<span class="comment"> *</span>
<span class="comment"> * License: You may use this code as you wish, provided you give credit where it&#39;s due.</span>
<span class="comment"> *</span>
<span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<span class="comment"></span>
<span class="comment"> * Xander Soldaat (mightor_at_gmail.com)</span>
<span class="comment"> * Dick Swan</span>
<span class="comment"> * 06 April 2010</span>
<span class="comment"> * version 0.2</span>
<span class="comment"> */</span>

<span class="preprocessor">#include &quot;<a class="code" href="hitechnic-sensormux_8h.html" title="Commonly used functions used by drivers.">drivers/hitechnic-sensormux.h</a>&quot;</span>
<span class="preprocessor">#include &quot;<a class="code" href="hitechnic-irseeker-v2_8h.html" title="HiTechnic IR Seeker V2 driver.">drivers/hitechnic-irseeker-v2.h</a>&quot;</span>

<span class="comment">// The sensor is connected to the first port</span>
<span class="comment">// of the SMUX which is connected to the NXT port S1.</span>
<span class="comment">// To access that sensor, we must use msensor_S1_1.  If the sensor</span>
<span class="comment">// were connected to 3rd port of the SMUX connected to the NXT port S4,</span>
<span class="comment">// we would use msensor_S4_3</span>

<span class="comment">// Give the sensor a nice easy to use name</span>
<span class="keyword">const</span> <a class="code" href="group__htsmux.html#gab5bad1759ac110c43e66c3ec54047f42">tMUXSensor</a> HTIRS2 = <a name="a0"></a><a class="code" href="group__htsmux.html#ggab5bad1759ac110c43e66c3ec54047f42a9bb0d1a5225e16291efdef5795191af1">msensor_S1_1</a>;

<span class="comment">// global variables</span>
<span class="keywordtype">string</span> sTextLines[8];

<span class="comment">// function prototypes</span>
<span class="keywordtype">void</span> displayText(<span class="keywordtype">int</span> nLineNumber, <span class="keyword">const</span> <span class="keywordtype">string</span> cChar, <span class="keywordtype">int</span> nValueDC, <span class="keywordtype">int</span> nValueAC);
<span class="keywordtype">void</span> displayText3(<span class="keywordtype">int</span> nLineNumber, <span class="keyword">const</span> <span class="keywordtype">string</span> cChar, <span class="keywordtype">int</span> nValueDC, <span class="keywordtype">int</span> nValueAC, <span class="keywordtype">int</span> nValueEnh);
<span class="keywordtype">void</span> displayInstructions();

<span class="comment">// main task</span>
task main ()
{
  <span class="keywordtype">int</span> _dirDC = 0;
  <span class="keywordtype">int</span> _dirAC = 0;
        <span class="keywordtype">int</span> dcS1, dcS2, dcS3, dcS4, dcS5 = 0;
        <span class="keywordtype">int</span> acS1, acS2, acS3, acS4, acS5 = 0;
        <span class="keywordtype">int</span> _dirEnh, _strEnh;

  <span class="comment">// show the user what to do</span>
  displayInstructions();

  eraseDisplay();
  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; 8; ++i)
    sTextLines[i] = <span class="stringliteral">&quot;&quot;</span>;

  <span class="comment">// display the current DSP mode</span>
  <span class="comment">// When connected to a SMUX, the IR Seeker V2 can only be</span>
  <span class="comment">// used in 1200Hz mode.</span>
  nxtDisplayTextLine(0, <span class="stringliteral">&quot;    DC 1200 Enh&quot;</span>);

  <span class="comment">// The sensor is connected to the first port</span>
  <span class="comment">// of the SMUX which is connected to the NXT port S1.</span>
  <span class="comment">// To access that sensor, we must use msensor_S1_1.  If the sensor</span>
  <span class="comment">// were connected to 3rd port of the SMUX connected to the NXT port S4,</span>
  <span class="comment">// we would use msensor_S4_3</span>

  <span class="keywordflow">while</span> (<span class="keyword">true</span>)
  {
    <span class="comment">// Read the current non modulated signal direction</span>
    _dirDC = <a name="a1"></a><a class="code" href="group__htirs2.html#gaf6e97818d7ba93fa318206d617b677c9">HTIRS2readDCDir</a>(HTIRS2);
    <span class="keywordflow">if</span> (_dirDC &lt; 0)
      <span class="keywordflow">break</span>; <span class="comment">// I2C read error occurred</span>

    <span class="comment">// read the current modulated signal direction</span>
    _dirAC = <a name="a2"></a><a class="code" href="group__htirs2.html#gaa18081a7069fb59d4400b7144bf88fa4">HTIRS2readACDir</a>(HTIRS2);
    <span class="keywordflow">if</span> (_dirAC &lt; 0)
      <span class="keywordflow">break</span>; <span class="comment">// I2C read error occurred</span>

    <span class="comment">// Read the individual signal strengths of the internal sensors</span>
    <span class="comment">// Do this for both unmodulated (DC) and modulated signals (AC)</span>
    <span class="keywordflow">if</span> (!<a name="a3"></a><a class="code" href="group__htirs2.html#ga032e3ca0035e042cc5f87b9b1ce2f1c9">HTIRS2readAllDCStrength</a>(HTIRS2, dcS1, dcS2, dcS3, dcS4, dcS5))
      <span class="keywordflow">break</span>; <span class="comment">// I2C read error occurred</span>
    <span class="keywordflow">if</span> (!<a name="a4"></a><a class="code" href="group__htirs2.html#gaa206e9966662674e5be0ce878ba5c6de">HTIRS2readAllACStrength</a>(HTIRS2, acS1, acS2, acS3, acS4, acS5 ))
      <span class="keywordflow">break</span>; <span class="comment">// I2C read error occurred</span>

    <span class="comment">// Read the Enhanced direction and strength</span>
                <span class="keywordflow">if</span> (!<a name="a5"></a><a class="code" href="group__htirs2.html#ga227d4dead1df386fc19ecdbb26017aa8">HTIRS2readEnhanced</a>(HTIRS2, _dirEnh, _strEnh))
      <span class="keywordflow">break</span>; <span class="comment">// I2C read error occurred</span>

    displayText3(1, <span class="stringliteral">&quot;D&quot;</span>, _dirDC, _dirAC, _dirEnh);
    displayText(2, <span class="stringliteral">&quot;0&quot;</span>, dcS1, acS1);
    displayText(3, <span class="stringliteral">&quot;1&quot;</span>, dcS2, acS2);
    displayText3(4, <span class="stringliteral">&quot;2&quot;</span>, dcS3, acS3, _strEnh);
    displayText(5, <span class="stringliteral">&quot;3&quot;</span>, dcS4, acS4);
    displayText(6, <span class="stringliteral">&quot;4&quot;</span>, dcS5, acS5);

    <span class="keywordflow">if</span> (<a name="a6"></a><a class="code" href="group__htsmux.html#gaef01450d36623d782b4bf1ad4f964246">HTSMUXreadPowerStatus</a>(HTSMUX))
      nxtDisplayTextLine(7, <span class="stringliteral">&quot;Batt: bad&quot;</span>);
    <span class="keywordflow">else</span>
      nxtDisplayTextLine(7, <span class="stringliteral">&quot;Batt: good&quot;</span>);
  }
}

<span class="comment">// Display the instructions to the user</span>
<span class="keywordtype">void</span> displayInstructions()
{
  nxtDisplayCenteredTextLine(0, <span class="stringliteral">&quot;HiTechnic&quot;</span>);
  nxtDisplayCenteredBigTextLine(1, <span class="stringliteral">&quot;IRSeekr2&quot;</span>);
  nxtDisplayCenteredTextLine(3, <span class="stringliteral">&quot;SMUX Test&quot;</span>);
  nxtDisplayCenteredTextLine(5, <span class="stringliteral">&quot;Connect SMUX to&quot;</span>);
  nxtDisplayCenteredTextLine(6, <span class="stringliteral">&quot;S1 and sensor to&quot;</span>);
  nxtDisplayCenteredTextLine(7, <span class="stringliteral">&quot;SMUX Port 1&quot;</span>);
  wait1Msec(2000);
}

<span class="comment">// Minimize LCD screen flicker by only updating LCD when data has changed</span>
<span class="keywordtype">void</span> displayText(<span class="keywordtype">int</span> nLineNumber, <span class="keyword">const</span> <span class="keywordtype">string</span> cChar, <span class="keywordtype">int</span> nValueDC, <span class="keywordtype">int</span> nValueAC)
{
  <span class="keywordtype">string</span> sTemp;

  StringFormat(sTemp, <span class="stringliteral">&quot;%4d %4d&quot;</span>, nValueDC, nValueAC);
  <span class="comment">// Check if the new line is the same as the previous one</span>
  <span class="comment">// Only update screen if it&#39;s different.</span>
  <span class="keywordflow">if</span> (sTemp != sTextLines[nLineNumber])
  {
    <span class="keywordtype">string</span> sTemp2;

    sTextLines[nLineNumber] = sTemp;
    StringFormat(sTemp2, <span class="stringliteral">&quot;%s:%s&quot;</span>, cChar, sTemp);
    nxtDisplayTextLine(nLineNumber, sTemp2);
  }
}

<span class="comment">// Minimize LCD screen flicker by only updating LCD when data has changed</span>
<span class="keywordtype">void</span> displayText3(<span class="keywordtype">int</span> nLineNumber, <span class="keyword">const</span> <span class="keywordtype">string</span> cChar, <span class="keywordtype">int</span> nValueDC, <span class="keywordtype">int</span> nValueAC, <span class="keywordtype">int</span> nValueEnh)
{
  <span class="keywordtype">string</span> sTemp;

  StringFormat(sTemp, <span class="stringliteral">&quot;%4d %4d %3d&quot;</span>, nValueDC, nValueAC, nValueEnh);

  <span class="comment">// Check if the new line is the same as the previous one</span>
  <span class="comment">// Only update screen if it&#39;s different.</span>
  <span class="keywordflow">if</span> (sTemp != sTextLines[nLineNumber])
  {
    <span class="keywordtype">string</span> sTemp2;

    sTextLines[nLineNumber] = sTemp;
    StringFormat(sTemp2, <span class="stringliteral">&quot;%s:%s&quot;</span>, cChar, sTemp);
    nxtDisplayTextLine(nLineNumber, sTemp2);
  }
}

<span class="comment">/*</span>
<span class="comment"> * $Id: hitechnic-irseeker-v2-enhanced-SMUX-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
</pre></div> </div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:42 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
